#
#	redMine - Instant Mobile Feedback (IMF) Plugin
#	Author: Bartłomiej Twardowski
#	Date: 16/06/2010
#

require File.dirname(__FILE__) + '/imf_plugin_app_controller'

class ProjectController < ApplicationController

 accept_key_auth :list

  def list
  
  	curr_user = find_current_user
  	
  	#stupid workaround
  	if not curr_user
  		authorize
  	end
  	
  	logger.debug "CURRENT USER #{curr_user}"
  	
  	logger.info "Getting project list..."  	
  	projects = Project.find(:all, :joins => :enabled_modules,
                  				  :conditions => [ "enabled_modules.name = 'issue_tracking' AND #{Project.visible_by}"])
  	
  	logger.info "Listing project..."
  	projects.each do |p|
   		logger.debug "Project: #{p}"
	end
	
  	logger.debug "Request format: " + request.format
#    respond_to do |format|
#      format.html { 
#		render :template => 'issues/index.rhtml', :layout => !request.xhr? 
#	  }
#      format.xml  { 
#      	render :layout => false, :xml => projects 
#      }
#    end
	@xml = Builder::XmlMarkup.new
	@projects = projects
	render :xml => projects, :layout => false
  end
  
  
end
